// 使andriod和ios路由切换风格一致
import 'package:flutter/cupertino.dart';
import 'package:flutter_application/picture.dart';
import 'package:flutter_application/userInfo.dart';
import '../formPage.dart';
import '../searchPage.dart';
import '../newsPage.dart';
import '../enter.dart';
import '../login.dart';
import '../register.dart';
import '../userInfo.dart';

final Map routes = {
  '/enter': (context) => const EntePage(),
  '/search': (context) => const SearchPage(),
  '/form': (context, {arguments}) => FormPage(arguments: arguments),
  '/news': (context) => const NewsPage(),
  '/login': (context) => const LoginPage(),
  '/register': (context) => const RegisterPage(),
  '/userInfo': (context) => const UserInfoPage(),
  '/picture': (context) => const PicturePage(),
};

//固定写法,为了处理路由的参数.
// ignore: missing_return, top_level_function_literal_block
var onGenerateRoute = (RouteSettings settings) {
  final String? name = settings.name;
  final Function pageContentBuilder = routes[name];
  if (pageContentBuilder != null) {
    if (settings.arguments != null) {
      final Route route = CupertinoPageRoute(
          builder: (context) =>
              pageContentBuilder(context, arguments: settings.arguments));
      return route;
    } else {
      final Route route =
          CupertinoPageRoute(builder: (context) => pageContentBuilder(context));
      return route;
    }
  }
  return null;
};
